package com.okilo.online.app.dialog

import android.content.Context
import android.text.SpannableString
import android.view.LayoutInflater
import android.view.View
import com.okilo.online.app.common.OkiloComDlog
import com.okilo.online.app.databinding.OkiloDlogTipsBinding

/**
 * OkiloLoan
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：提示dialog
 */
class OkiloTipsDlog: OkiloComDlog {

    private lateinit var binding: OkiloDlogTipsBinding
    private var callback: IOkiloTipsClickCallback? = null

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IOkiloTipsClickCallback?) : super(context) {
        this@OkiloTipsDlog.callback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        dialogRemark = remark
    }
    constructor(context: Context, remark: String, callback: IOkiloTipsClickCallback?) : super(context) {
        this@OkiloTipsDlog.callback = callback
        dialogRemark = remark
    }

    override val dialogName: String = "Tips"

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IOkiloTipsClickCallback){
        this.callback = callback
    }

    override fun createOkiloContentView(): View {
        binding = OkiloDlogTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initializeOkiloViews() {
    }

    override fun setupOkiloEventListeners() {
        setOnClickListener(binding.okiloTipsCancel) //取消
        setOnClickListener(binding.okiloTipsConfirm) //ok
    }

    override fun loadOkiloData() {
    }

    override fun onOkiloEventViewClick(v: View?) {
        dismiss()
        if(callback != null){
            callback?.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun sOkiloDlogTipsEventRemark(remark: String){
        dialogRemark = remark
    }

    /**
     * 设置提示图标
     */
    fun sOkiloDlogTipsIconResource(resId: Int){
        binding.okiloTipsIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun sOkiloDlogTipsTitleText(title: String){
        binding.okiloTipsTitle.text = title
    }

    /**
     * 设置提示title
     */
    fun sOkiloDlogTipsTitleText(title: String, color: Int){
        sOkiloDlogTipsTitleText(title)
        binding.okiloTipsTitle.setTextColor(color)
    }

    /**
     * 设置提示语
     */
    fun sOkiloDlogTipsMsgText(tips: String){
        binding.okiloTipsText.text = tips
    }

    /**
     * 设置提示语
     */
    fun sOkiloDlogTipsMsgText(spannableString: SpannableString){
        binding.okiloTipsText.text = spannableString
    }

    /**
     * 设置提示语对齐方式
     */
    fun sOkiloDlogTipsMsgGravity(gravity: Int){
        binding.okiloTipsText.gravity = gravity
    }

    /**
     * 设置显示一个按钮或两个按钮
     */
    fun iOkiloDlogTipsDoubleButton(isDouble: Boolean){
        if (isDouble){//显示两个按钮
            binding.okiloTipsCancel.visibility = View.VISIBLE
            binding.okiloTipsConfirm.visibility = View.VISIBLE
        } else {
            binding.okiloTipsCancel.visibility = View.GONE
            binding.okiloTipsConfirm.visibility = View.VISIBLE
        }
    }

    /**
     * 设置取消文字
     */
    fun sOkiloDlogTipsButtonCancelText(text: String){
        binding.okiloTipsCancel.text = text
    }

    /**
     * 设置ok文字
     */
    fun sOkiloDlogTipsButtonConfirmText(text: String){
        binding.okiloTipsConfirm.text = text
    }

    interface IOkiloTipsClickCallback {
        //按钮点击
        fun onClick(view: View?)
    }
}